﻿package com.badibadi.fragment;

import com.badibadi.activity.AfterLandingActivity;
import com.badibadi.activity.Fingerpost_Activity;
import com.badibadi.activity.ForgotPassWordActivity;
import com.badibadi.activity.LogoActivity;
import com.badibadi.activity.PrivacySettingActivity;
import com.badibadi.activity.ToResetYourPasswordActivity;
import com.badibadi.adapter.AfterLandingRightSlidingSettingAdapter;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wyy.twodimcode.FinishListener;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 登陆后右滑点击设定按钮
 * 
 * @author Administrator
 * 
 */
public class AfterLandingRightSlidingSettingFragment extends BaseFragment {
	private Intent intent = null;
	private ListView mListView;
	private LinearLayout setting_layout;
	private AfterLandingRightSlidingSettingAdapter alrssAdapter;
	private Button fragment_afterlanding_setting_return;

	static AfterLandingRightSlidingSettingFragment afterLandingRightSlidingSettingFragment;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		alrssAdapter = new AfterLandingRightSlidingSettingAdapter(getActivity());

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_afterlanding_setting,
				null);
		setting_layout = (LinearLayout) view.findViewById(R.id.setting_layout);
		fragment_afterlanding_setting_return = (Button) view
				.findViewById(R.id.afterlanding_setting_return);
		fragment_afterlanding_setting_return
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						((AfterLandingActivity) getActivity())
								.settingRightslidingMenu();
					}
				});
		mListView = (ListView) view
				.findViewById(R.id.after_landing_rightsliding_click_setting_fragment);
		alrssAdapter = new AfterLandingRightSlidingSettingAdapter(getActivity());
		mListView.setAdapter(alrssAdapter);
		mListView.setItemsCanFocus(false);
		mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long arg3) {
				// TODO Auto-generated method stub
				// Toast.makeText(getActivity(), "" + position, 0).show();
				setOnClickItemButton(position);

			}
		});

		mListView.setLayoutParams(new LinearLayout.LayoutParams(
				(int) (getScreenW() - DisplayUtil.dip2px(getActivity(), 50)),
				LinearLayout.LayoutParams.WRAP_CONTENT));

		return view;
	}

	private float getScreenW() {
		DisplayMetrics metrics = new DisplayMetrics();// 获取屏幕宽高
		getActivity().getWindowManager().getDefaultDisplay()
				.getMetrics(metrics);// 1。获取窗口管理器，2默认的屏幕，3获取屏幕的大小（赋值给metrcs）

		float ScreenW = metrics.widthPixels;
		return ScreenW;
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	public interface CallBack {
		public void getMessage(String msg);
	}

	public static AfterLandingRightSlidingSettingFragment getInstance() {
		if (afterLandingRightSlidingSettingFragment == null) {
			return new AfterLandingRightSlidingSettingFragment();
		}
		return afterLandingRightSlidingSettingFragment;
	}

	/**
	 * 设置ListView的点击事件
	 * 
	 * @param pos
	 */
	protected void setOnClickItemButton(int pos) {
		// TODO Auto-generated method stub

		switch (pos) {
		// 清理缓存
		case 0:
			try {
				ImageLoader.getInstance().clearDiscCache();
				ImageLoader.getInstance().clearMemoryCache();
				Thread.sleep(3000);
				Utils.showMessage(getActivity(),
						getResources().getString(R.string.l_xa8));
			} catch (Exception e) {
				// TODO: handle exception
			}

			break;
		// 重设密码
		case 1:
			intent = new Intent(getActivity(),
					ToResetYourPasswordActivity.class);
			break;
		// 隐私设定
		case 2:
			intent = new Intent(getActivity(), PrivacySettingActivity.class);
			break;
		// 更新
		case 3:
			UpdateManager manager = new UpdateManager(getActivity());
			manager.getApkInfo();
			break;
		// 意见反馈
		case 4:
			intent = new Intent(getActivity(), Fingerpost_Activity.class);
			intent.putExtra("panduan_id", "feedback");
			break;
//		// 语言切换
//		case 5:
//			Dialog d = new Dialog();
//			d.setOnDialogClistener(new Dialog.DialogClistener() {
//
//				@Override
//				public void ret() {
//					// TODO Auto-generated method stub
//
//				}
//
//				@Override
//				public void ok() {
//					// TODO Auto-generated method stub
//
////					((AfterLandingActivity) (getActivity())).exit();
////					((AfterLandingActivity) (getActivity())).OpenTheThirdPartySoftWare(((AfterLandingActivity)(getActivity())).BADIBADI_PAGENAME, ((AfterLandingActivity)(getActivity())).BADIBADI_Uri);
//		
//				}
//			});
//			d.LanguageSwitching(getActivity());
//
//			// new Dialog().LanguageSwitching(getActivity());
//			break;
		// 使用帮助
		case 5:
			intent = new Intent(getActivity(), Fingerpost_Activity.class);
			intent.putExtra("panduan_id", "Maps");
			break;
		// 关于我们
		case 6:
			intent = new Intent(getActivity(), Fingerpost_Activity.class);
			intent.putExtra("panduan_id", "aboutUs");
			break;
		// 隐私声明
		case 7:
			intent = new Intent(getActivity(), Fingerpost_Activity.class);
			intent.putExtra("panduan_id", "statement");
			break;
		}
		if (intent != null)
			getActivity().startActivity(intent);
		intent = null;
	}
}
